package com.star.uc.contract.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.io.Serializable;

/**
 * 登录请求
 *
 * @author zhouhengzhe
 * @version 1.0
 * @date 2023/10/18 17:58
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "登录请求")
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
public class LoginRequest extends BaseRequest {
    /**
     * 登录类型
     *
     * @see com.star.uc.contract.enums.LoginTypeEnum
     */
    @NotBlank(message = "登录类型不能为空")
    @Schema(description = "登录类型")
    private String loginType;

    /**
     * 访问AuthorizeUrl后回调时带的参数code，除了下面的登录方式外，其他的都要传code，下面的登录方式不需要
     */
    @Schema(description = "访问AuthorizeUrl后回调时带的参数code，除了下面的登录方式外，其他的都要传code，下面的登录方式不需要")
    private String code;

    /**
     * 访问AuthorizeUrl后回调时带的参数state，用于和请求AuthorizeUrl前的state比较，防止CSRF攻击，其他的都要传state，下面的登录方式不需要
     */
    @Schema(description = "访问AuthorizeUrl后回调时带的参数state，用于和请求AuthorizeUrl前的state比较，防止CSRF攻击,除了下面的登录方式外，其他的都要传state，下面的登录方式不需要")
    private String state;

    @Schema(description = "Phone登录请求方式")
    private PhoneRequest phoneRequest;

    @Schema(description = "Username登录请求方式")
    private UsernameRequest usernameRequest;

    @Schema(description = "Email登录请求方式")
    private EmailRequest emailRequest;

    @Schema(description = "OneClickPhone登录请求方式")
    private OneClickPhoneRequest oneClickPhoneRequest;

    @Schema(description = "Quick登录请求方式")
    private QuickRequest quickRequest;


    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Schema(description = "Phone登录请求方式")
    public static class PhoneRequest implements Serializable {

        @Schema(description = "国家区号")
        private String countryCode;

        @Schema(description = "手机号码")
        private String phone;

        @Schema(description = "验证码")
        private Integer code;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Schema(description = "Username登录请求方式")
    public static class UsernameRequest implements Serializable {

        @Schema(description = "邮件(email)/手机号(国家区号,手机号码)")
        private String username;

        @Schema(description = "密码")
        private String password;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Schema(description = "Email登录请求方式")
    public static class EmailRequest implements Serializable {

        @Schema(description = "邮件(email)")
        private String email;

        @Schema(description = "验证码")
        private Integer code;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Schema(description = "Quick登录请求方式")
    public static class QuickRequest implements Serializable {
        @Schema(description = "国家区号")
        private String countryCode;

        @Schema(description = "手机号码")
        private String phone;
    }

    /**
     * <a href="https://blog.51cto.com/u_16152740/6426855">...</a>
     */
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Schema(description = "OneClickPhone登录请求方式")
    public static class OneClickPhoneRequest implements Serializable {

        @Schema(description = "签名")
        private String signName;

        @Schema(description = "方案号")
        private String sceneCode;

        @Schema(description = "Token有效期")
        private Long expire;

        @Schema(description = "短信模板Code")
        private String smsTemplateCode;

        @Schema(description = "短信验证码有效期")
        private Integer smsCodeExpire;

        @Schema(description = "一键登录内部的ios请求参数")
        private IosOneClickPhoneRequest ios;

        @Schema(description = "一键登录内部的安卓请求参数")
        private AndroidOneClickPhoneRequest android;

        @Data
        @AllArgsConstructor
        @NoArgsConstructor
        @Schema(description = "一键登录内部的ios请求参数")
        public static class IosOneClickPhoneRequest implements Serializable{

            @Schema(description = "iOS应用ID")
            private String bundleId;
        }

        @Data
        @AllArgsConstructor
        @NoArgsConstructor
        @Schema(description = "一键登录内部的安卓请求参数")
        public static class AndroidOneClickPhoneRequest implements Serializable{

            @Schema(description = "包名,Android时必传")
            private String packageName;
        }
    }
}
